<template>
  <div class="home">
    <header>
      <i class="iconfont icon-iconfontseacher"></i>
      <input type="text" class="searchBar" placeholder="search" @click="$router.push('/search')">
      <i class="iconfont icon-nav" @click="sheetVisible=!sheetVisible"></i>
      <mt-actionsheet :actions="actions" v-model="sheetVisible">
      </mt-actionsheet>
    </header>

    <div class="lists">
      <!-- 获取新添加人口 -->
      <index-list :data="addFriends" :useLazyLoad="true" @choose="onChoose" v-if="addFriends.length"></index-list>
    </div>

    <div class="bottom">
      <div class="item active">
        <i class="count" v-if="$store.state.app.addFrendsCount">{{$store.state.app.addFrendsCount}}</i>
        <i class="iconfont icon-dingdanicon"></i>
        <div>通讯录</div>
      </div>
     <!--  <div class="item" @click="$router.push('/talkList')">
        <i class="iconfont icon-kefuzhongxinicon"></i>
        <div>聊天记录</div>
      </div> -->
    </div>
  </div>
</template>

<script>
  // @ is an alias to /src
  import HelloWorld from "@/components/HelloWorld.vue";
  import indexList from "./IndexList";
  import playerList from "./testData.json";
  import { getAddFriends } from "./service";
  import auth from '../../utils/auth';
  export default auth({
    name: "home",
    components: {
      indexList
    },
    methods: {
      onChoose(user) {
        this.$router.push(`/talk/${user.objectId}`);
      }
    },
    async mounted() {
      var addFriends = await getAddFriends();
      this.addFriends = addFriends;
    },
    data() {
      var self = this;
      return {
        addFriends: [],
        playerList,
        actions: [
          {
            name: "个人设置",
            method() {
              self.$router.push("/self");
            }
          }
        ],
        sheetVisible: false
      };
    }
  });
</script>
<style lang="less" scoped>
  header {
    padding-left: 15px;
    padding-right: 15px;
    height: 60px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid #eee;
    box-shadow: 1px 1px 1px #eee;

    .searchBar {
      border: none;
      background: #eee;
      border-radius: 50px;
      flex: 1;
      padding-left: 20px;
      margin-left: 15px;
      margin-right: 15px;
    }
  }

  .bottom {
    background: #fff;
    justify-content: center;
    padding-left: 10px;
    padding-right: 10px;
    display: flex;
    position: fixed;
    bottom: 0;
    width: 100%;
    border-top: 1px solid #eee;
    max-width: 750px;
    height: 60px;
    align-items: center;

    .item {
      &:last-child {
        margin-left: 50px;
      }

      .count {
        position: absolute;
        background: red;
        padding: 5px;
        width: 20px;
        height: 20px;
        display: flex;
        align-self: center;
        align-items: center;
        border-radius: 100%;
        right: -10px;
        top: -0px;
        color: #fff;
        font-size: 12px;
      }

      i {
        font-size: 20px;
      }

      position: relative;
      display: flex;
      align-items: center;
      flex-direction: column;
      justify-content: center;

      &.active {
        color: green;
      }
    }
  }
</style>